package com.zx.task.manager.mapstruct;

import com.zx.task.manager.enums.TaskOperationTypeEnum;
import com.zx.task.manager.model.TaskOperations;
import com.zx.task.manager.param.TaskOperationsParam;
import com.zx.task.manager.vo.TaskOperationsVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

/**
 * <p>
 * description: 任务操作记录映射 <br>
 * create: 2025-10-13 20:15
 * </p>
 *
 * @author zhou  xun
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TaskOperationsMapStructMapper {
    TaskOperationsMapStructMapper INSTANCE = Mappers.getMapper(TaskOperationsMapStructMapper.class);

    /**
     * 将TaskOperationsParam转换为TaskOperations实体
     *
     * @param taskOperationsParam 任务操作记录参数
     * @return TaskOperations实体
     */
    TaskOperations taskOperationsParamToTaskOperations(TaskOperationsParam taskOperationsParam);

    /**
     * 将TaskOperations实体转换为TaskOperationsVO视图对象
     *
     * @param taskOperations 任务操作记录实体
     * @return TaskOperationsVO视图对象
     */
    TaskOperationsVO taskOperationsToTaskOperationsVO(TaskOperations taskOperations);

    /**
     * 在映射完成后，设置描述性字段
     *
     * @param taskOperations   任务操作记录实体
     * @param taskOperationsVO 任务操作记录VO
     */
    @AfterMapping
    default void setDescriptions(TaskOperations taskOperations, @MappingTarget TaskOperationsVO taskOperationsVO) {
        // 设置操作类型描述
        TaskOperationTypeEnum operationTypeEnum = TaskOperationTypeEnum.getEnumByCode(taskOperations.getOperationType());
        if (operationTypeEnum != null) {
            taskOperationsVO.setOperationTypeDesc(operationTypeEnum.getDesc());
        }
    }
}